#include "Log.h"
#include "Connect.h"
#include "Message.h"
#include "Task.h"

namespace sevent{


Task::Task(Connect *c, char* message, const TaskFunc &f)
:_connect(c), _message(message), _taskFunc(f){
	_connect->addCount();
}

Task::~Task(){
	if(_message)
		delete [] _message; //here to delete ?
	_connect->close();
}

int Task::execute(){
	LOG_DEBUG_VA("Task %x start execute", this);
	int ret;
	try{
		ret = _taskFunc(_connect, _message);
	}catch(exception &e) {
		std::cerr << "catch exception: " << e.what() << std::endl;
	}
	
	LOG_DEBUG_VA("Task %x execute over", this);
	return ret;
}


}

